
import sun.reflect.generics.tree.Tree;

import java.util.*;

/**
 * @Author 12629
 * @Description：
 */
public class BinaryTree {
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }


    public TreeNode createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        E.right = H;
        return A;
    }

    public void preOrder(TreeNode root) {
        if(root == null) return;
        System.out.print(root.val+" ");
        preOrder(root.left);
        preOrder(root.right);
    }
    /**
     * 将前序遍历的结果 存储到list当中
     * @param root
     * @return
     */
    List<TreeNode> ret = new ArrayList<>();
    public List<TreeNode> preOder2(TreeNode root) {
        if (root == null) return  ret;
        System.out.println(root.val+"");

        }


    }
   /* List<TreeNode> ret = new ArrayList<>();
    public List<TreeNode> preOrder2(TreeNode root) {
        if(root == null) return ret;
        //System.out.print(root.val+" ");
        ret.add(root);
        preOrder2(root.left);
        preOrder2(root.right);
        return ret;
    }*/

    public List<TreeNode> preOrder2(TreeNode root) {
        List<TreeNode> ret = new ArrayList<>();
        if(root == null) return ret;
        ret.add(root);
        List<TreeNode> leftTree = preOrder2(root.left);
        ret.addAll(leftTree);
        List<TreeNode> rightTree = preOrder2(root.right);
        ret.addAll(rightTree);
        return ret;
    }

    public void inOrder(TreeNode root) {
        if(root == null) return;
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }
    public void postOrder(TreeNode root) {
        if (root == null) return;
        inOrder(root.left);
        inOrder(root.right);
        System.out.print(root.val + " ");
    }


}